package biz.sdna.generatecode.core;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Properties;


import org.hibernate.HibernateException;
import org.hibernate.connection.ConnectionProvider;

public class GCConnectionProvider implements ConnectionProvider{
	private Properties prop = null;
	public void configure(Properties arg0) throws HibernateException {
		prop = arg0;
	}
	public Connection getConnection() throws SQLException {
		Connection conn = null;
		try {
			Driver driver = (Driver)GCClassLoader.gccl.loadClass(prop.getProperty("hibernate.connection.driver_class")).newInstance();
			Properties props = new Properties();
            props.setProperty("user", prop.getProperty("hibernate.connection.username"));
            props.setProperty("password", prop.getProperty("hibernate.connection.password"));
            
            conn = driver.connect(prop.getProperty("hibernate.connection.url"), props);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return conn;
	}
	public void closeConnection(Connection arg0) throws SQLException {
		try {
			arg0.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void close() {
	}
	public boolean supportsAggressiveRelease() {
		return false;
	}
}
